//
//  JKVisterChecker.m
//  VistorDemo
//
//  Created by Jack on 2021/8/6.
//

#import "JKVisterChecker.h"
#import "JKUserManager.h"
#import "JKLoginViewController.h"

@implementation JKVisterChecker

+ (void)addToDoThingsAfterLogin:(void (^)(void))afterLogin{
    //1.获取用户信息，根据自己的需求来
    JKUser *user = [[JKUserManager sharedUserManager] currentUser];
    if (!user) {
        //2-1-1 需要登陆的情况
        JKLoginViewController *vc = [[JKLoginViewController alloc] init];
        vc.modalPresentationStyle = UIModalPresentationFullScreen;
        vc.loginCallback = ^(BOOL loginSuccess) {
            if (loginSuccess) {
                //2-1-2 成功登录后调用afterLogin()，外部继续登录后需要做的事情，例如进入OrderList
                if (afterLogin) {
                    afterLogin();
                }
            }
        };
        UIWindow *window = [[UIApplication sharedApplication].windows firstObject];
        [window.rootViewController presentViewController:vc animated:YES completion:NULL];
    }else{
        //2-2-1 用户已经登陆，外部直接执行后续任务
        if (afterLogin) {
            afterLogin();
        }
    }
}

@end
